from django.db import models

from apps.project.models import Project

# Create your models here.


class Interface(models.Model):
    """
    接口模型
    """
    method_type = (
        ('get', 'GET'),
        ('post', 'POST'),
        ('put', 'PUT'),
        ('patch', 'PATCH'),
        ('delete', 'DELETE')
    )

    name = models.CharField(max_length=30, verbose_name=u'接口名称')
    url = models.CharField(max_length=100, verbose_name=u'请求地址')
    headers = models.CharField(max_length=50, verbose_name=u'头部信息', blank=True, null=True)
    params = models.CharField(max_length=200, verbose_name=u'请求参数', blank=True, null=True)
    files = models.FileField(verbose_name=u'文件', blank=True, null=True)
    project = models.ForeignKey(Project, verbose_name=u'测试项目', on_delete=models.CASCADE)
    method = models.CharField(choices=method_type, max_length=20, verbose_name=u'请求方式')
    response_headers = models.CharField(max_length=200, blank=True, null=True, verbose_name='响应头部')
    response_params = models.CharField(max_length=200, blank=True, null=True, verbose_name='响应参数')
    add_time = models.DateTimeField(auto_now_add=True, verbose_name=u'创建时间')
    edit_time = models.DateTimeField(auto_now=True, verbose_name=u'修改时间')

    class Meta:
        db_table = 't_interface'
        verbose_name = '接口库'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
